package com.longge.wechat.thread;

public class ThreadSync implements Runnable{
	Timer timer = new Timer();
	public static void main(String[] args) {
		ThreadSync ts = new ThreadSync();
		Thread t1 = new Thread(ts);
		Thread t2 = new Thread(ts);
		t1.setName("t1");
		t2.setName("t2");
		t1.start();
		t2.start();
	}
	
	@Override
	public void run() {
		timer.add(Thread.currentThread().getName());
	}
}


class Timer {
	private static int num = 0;
	
	public void add(String name) {
		synchronized (this) {
			num ++;
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
			
			}
			System.out.println(name + "你是当前第"+num+"个调用的线程");
		}
	}
}